package com.symaster.swingalixcomponent.util;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

/**
 * @author yinmiao
 * @version 2024/5/3
 */
public class ImageLoadUtil {

    public static void main(String[] args) {
        LookAndFeel lookAndFeel = UIManager.getLookAndFeel();
        System.out.println(lookAndFeel);
    }

    private static void log(Object str) {
        System.out.println(str);
    }

    public static ImageIcon loadImage(Class<?> clazz, String iconName, int w, int h) {
        URL resource = clazz.getResource("triangle.png");
        if (resource == null) {
            return null;
        }

        try (InputStream inputStream = resource.openStream()) {
            Image read = ImageIO.read(inputStream).getScaledInstance(w, h, Image.SCALE_SMOOTH);
            return new ImageIcon(read);
        } catch (IOException e) {
            e.printStackTrace(System.err);
            return null;
        }
    }
}
